package jdk8.method.reference.demo07.array.method.reference;

import java.util.Arrays;

/**
 * 数组构造器的引用
 **/
public class Demo {
    public static int[] createArray(int length, ArrayBuilder builder) {
        return builder.builderArray(length);
    }

    public static void main(String[] args) {
        int[] array = createArray(3, length -> {
            return new int[length];
        });

        System.out.println(array.length);

        /**
         * 方法引用优化Lambda
         * 1. 已知创建的是int[]
         * 2. 长度已知
         * 就可以引用int[]的构造, new
         */
        int[] array2 = createArray( 3,int[]::new);

        System.out.println(Arrays.toString(array2));
        System.out.println(array2.length);
    }
}
